<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/commonPage/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link rel="stylesheet" href="${base }/style/mainPage.css">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中国教育创新校企联盟</title>
</head>
<body class="inner-container">
	<div class="pageInside">
		<div class="schoolEnterprise" style="min-height: 548px;">
			<!-- 轮播图实现模块 -->
			<!-- 条目中可以是任意内容，如：<img src=""> -->
			<div class="layui-carousel" id="carousel">
				<div carousel-item class="carousel-items"></div>
			</div>

			<!-- 最新资讯的新闻窗模块 -->
			<div class="module-information-container">
				<div class="module-information-title">
					<h3>最新资讯新闻一览</h3>
					<a onclick="navbarChange()">更多>></a>
				</div>
				<div class="information-items"></div>
			</div>

			<!-- 历史大事件模块 -->
			<div class="module-history-event-container">
				<div class="module-history-event-title">
					<h3>往期活动一览</h3>
				</div>
				<div class="history-event-items">
					<div class="layui-row layui-col-space20" id="history-event-list"></div>
					<div id="page-history" style="float: right; padding-right: 50px"></div>
				</div>
			</div>
		</div>
	</div>

	<div id="footer-div" style="width: 100%; height:8%; background: #eeeeee; overflow: hidden; ">
		<div style="height: 100%; width: 60%; margin: 0 auto; padding: 20px; vertical-align: center; text-align: center;">
			中国创新校企联盟&nbsp;@<a style="color: black;" href="http://www.beian.miit.gov.cn/">黔ICP备18008082号-2</a>
		</div>
	</div>

</body>

<script>
	$.ajaxSettings.async = false; //取消异步，用以获取项目数据

	var rotationData; //轮播图数据
	var informationData; //最新资讯的新闻数据
	var historyEventData; //历史大事件数据

	$.getJSON("${base }/rotation/getRotationAction", function(rotationdata) { //获取轮播图数据
		rotationData = rotationdata;
	});

	$.getJSON("${base }/information/getInformationAction", function(informationdata) { //获取最新资讯信息数据
		informationData = informationdata;
	});

	$.getJSON("${base }/history-event/getHistoryEventAction", function(historyeventdata) { //获取历史大事件数据
		historyEventData = historyeventdata;
	});

	
	var rotationBody = '';
	var informationBody = '';

	$.each(rotationData, function(index, val) { //将轮播图的所有数据遍历加入
		rotationBody += '<div><img src="' + val.imgUrl + '"></div>'
	})
	$('.carousel-items').append(rotationBody); //将遍历后的所有轮播图数据一次性加入到代码里面

	$.each(informationData, function(index, val) { //将最新资讯的所有数据遍历加入
		informationBody += '<div class="information-item" onclick="getInformationData(this)">' + '<p id="information-id" class="layui-hide">' + val.id + '</p>'
				+ '<div class="information-img img-transform"><img src="'+val.imgUrl+'"></div>' + '<div class="information-content">' + '<div class="information-title"><h2>' + val.title
				+ '</h2></div>' + '<div class="information-time"><h3>' + dateFormat(val.time).substr(0, 4) + '年' + dateFormat(val.time).substr(5, 2) + '月' + dateFormat(val.time).substr(8, 2) + '</h3></div>'
				+ '<div class="information-context"><p>' + delHtmlTag(val.context) + '</p></div>' + '</div>' + '</div>'
	})
	$('.information-items').append(informationBody); //将遍历后的所有资讯数据一次性加入到代码里面

	layui.use('carousel', function() { //首页轮播图功能实现
		var carousel = layui.carousel;
		//建造实例
		carousel.render({
			elem : '#carousel',
			width : '100%',//设置容器宽度
			height : '100%',
			arrow : 'hover' //始终显示箭头
			,interval : 1500
		// ,anim: 'fade' //切换动画方式
		});
	});

	layui.use('laypage', function() {
		var laypage = layui.laypage;
		//历史大事件数据分页
		laypage.render({
			elem : 'page-history',
			count : historyEventData.length,
			limit : 6,
			jump : function(obj) {
				document.getElementById('history-event-list').innerHTML = function() {
					var arr = [], thisdata = historyEventData.concat().splice(obj.curr * obj.limit - obj.limit, obj.limit);
					layui.each(thisdata, function(index, item) {
						arr.push('<div class="layui-col-xs6 layui-col-sm4 layui-col-md4 layui-col-lg4 img-transform" onclick="getGroupProject(this)">' + '<div class="item-data">'
								+ '<img src="'+item.imgUrl+'" class="event-cover">' + '<p id="id" class="layui-hide">' + item.id + '</p>'
								+ '<div style="background-color: white">' + '<p class="event-time">' + item.time.substr(0, 4) + '年' + item.time.substr(5, 2) + '月'
								+ item.time.substr(8, 2) + '</p>' + '<p class="event-info">' + item.context + '</p>' + '</div>' + '</div>' + '</div>')
					}); 
					return arr.join('');
				}();
			}
		});
		//end:历史大事件数据分页
	});

	//$.ajaxSettings.async = true; //获取项目数据完毕，开启异步
	
	function getInformationData(ele) { //获取点击最新新闻所对应的数据并跳转到指定页面展示
		var data = informationData.find(function(item) { //获取点击最新新闻所对应的数据
			return item.id == $($(ele).find("#information-id")[0]).html();
		});

		window.location.href = 'informationDetail?id=' + data.id; //带上点击信息的id跳转到新页面
	}
	
	function navbarChange() { //实现点击后，导航栏跳转到指定的那一栏
		parent.window.navbarChangeFormIframe('unionDynamic');
	}
</script>
</html>